<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Admin extends CI_Controller {

    protected $smarty;

    public function __construct() {
        parent::__construct();
        require_once 'smartyLoader.php';
        $this->smarty = $smarty;
        $this->user->isAccessBackOffice($this->smarty);
        $this->load->model('equipaModel');
        $this->load->model('respostaModel');
    }

    public function index() {
        
        $this->smarty->assign("templateActivo", "inicial.tpl.html");
        $this->root();   
    }
    
    private function root(){
         // temporario... ainda nao sei se tenho tempo para refazer area admin com grid 360
        $css = array("css/960grid/960.css");
        $this->smarty->assign("cssFileList", $css);
        
        $respostasPendentes = $this->respostaModel->loadPending();
        $this->smarty->assign("respostasPendentes", $respostasPendentes);

        $equipasInactivas = $this->equipaModel->loadAllInactive();
        $this->smarty->assign("equipasInactivas", $equipasInactivas);
       
        
        $this->smarty->display('admin/header.tpl.html');
        $this->smarty->display('admin/main.tpl.html');
        $this->smarty->display('admin/footer.tpl.html');
    }

    public function ativarAjax() {
         
        $var = $this->equipaModel->ativarEquipa($_POST['vid']);
        $this->smarty->assign("templateActivo", "inicial.tpl.html");
        $this->root();   
        
    }

    public function corrigir(){
        
        $utilizador = $this->session->all_userdata();
        $uid = $utilizador['uid'];
        
        $this->respostaModel->corrigir($_POST['vid'], $_POST['pontuacao'], $uid);
        $this->smarty->assign("templateActivo", "inicial.tpl.html");
        $this->root();
    }
}

?>
